package com.lulu.baselib.util;

import android.content.Context;

/**
 * Author: XuChang
 * Date: 2019/10/23 21:21
 * Email: 123286473@qq.com
 * Description:
 * History:
 */
public class DimensUtil {
    /**
     * dp单位转成px
     *
     * @param context context
     * @param dp      dp值
     * @return px值
     */
    public static int dp2px(Context context, int dp) {
        return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f);
    }

    /**
     * sp转为px
     *
     * @param context
     * @param spValue
     * @return
     */
    public static int sp2px(Context context, float spValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }
}
